package binary_tree.LeetCode;

import java.util.ArrayList;
import java.util.List;
import java.util.Stack;

//class TreeNode {
//      int val;
//      TreeNode left;
//      TreeNode right;
//      TreeNode() {}
//      TreeNode(int val) { this.val = val; }
//      TreeNode(int val, TreeNode left, TreeNode right) {
//          this.val = val;
//          this.left = left;
//          this.right = right;
//      }
//  }
public class Num144 {
    public List<Integer> preorderTraversal(TreeNode root) {
    List<Integer> res=new ArrayList<>();
    pre(root,res);
    return res;
    }
    public void pre(TreeNode root,List<Integer> list){
        if(root==null){
            return ;
        }
        list.add(root.val);
        pre(root.left,list);
        pre(root.right,list);
    }
}
